package com.deyang.mycommon.ui.activity.study;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.deyang.mycommon.R;
import com.deyang.mycommon.entity.Phone;
import com.deyang.mycommon.mvp.presenter.PhoneAddressPresenter;
import com.deyang.mycommon.mvp.view.PhoneAddressView;
import com.deyang.mycommon.ui.baseui.BaseActivity;
import com.deyang.mycommon.util.DialogUtil;
import com.deyang.mycommon.widget.StateButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author 王德阳
 * @createDate 2018/6/19 17:18
 * @desc 手机号码归属地查询
 */
public class PhoneAddressSeachActivity extends BaseActivity implements PhoneAddressView {


    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.btn_seach)
    StateButton btnSeach;
    @BindView(R.id.tv_shouji)
    TextView tvShouji;
    @BindView(R.id.tv_provinceArea)
    TextView tvProvinceArea;
    @BindView(R.id.tv_company)
    TextView tvCompany;
    @BindView(R.id.tv_cardtype)
    TextView tvCardtype;


    private PhoneAddressPresenter presenter;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_phone_address_seach);
        ButterKnife.bind(this);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        presenter = new PhoneAddressPresenter(this, this);
    }


    @OnClick({
            R.id.btn_seach,
    })
    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_seach:
                presenter.seachPhoneInfo(etPhone.getText().toString());
                break;
            default:
                break;
        }
    }

    @Override
    public void updateView() {
        Phone phone = presenter.getPhone();
        tvShouji.setText(phone.getShouji());
        tvProvinceArea.setText(phone.getProvince() + phone.getCity());
        tvCompany.setText(phone.getCompany());
        tvCardtype.setText(phone.getCardtype() + phone.getAreacode());
    }

    private Dialog loadingDialog;

    @Override
    public void showLoading() {
        if (loadingDialog == null) {
            loadingDialog = DialogUtil.getLoadingDialog(this);
        }
        loadingDialog.show();
    }

    @Override
    public void hideLoading() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
    }
}
